<template>
  <view>
    <van-uploader 
    v-model="imgPath"
    multiple
    :max-count="10"
    :accept="accept"
    :after-read="afterRead"
    ></van-uploader>
  </view>
</template>

<script setup>
import { ref } from 'vue';
import { uploadFile } from '@/utils/request';
defineProps({
  accept: '',
})
let urls = defineModel();

const imgPath = ref([]);

const afterRead = (fileObj) => {
  // 上传状态
  fileObj.status = 'uploading';
  // 状态提示
  fileObj.message = '上传中...';
  /* uni.compressImage({
    src: '/static/logo.jpg',
    quality: 80,
    success: res => {
      console.log(res.tempFilePath)
    }
  }) */

  // 上传接口调用
  uploadFile(fileObj.file).then(res => {
    // 上传成功
    fileObj.status = 'done';
    fileObj.message = '';
    // 存储返回数据
    fileObj.addInfo = res.url;
    urls.value.push(res.fileId);
  }).catch((err) => {
    console.log('catch',err);
    // 上传失败
    fileObj.status = 'failed';
    // 失败状态提示
    fileObj.message = '上传失败';
  });
}
</script>

<style lang="scss" scoped></style>